package td.pt.widget;

import td.client.ui.Button;
import td.domain.Topic;
import td.pt.widget.cell.TopicListing;

import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.cellview.client.CellList;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RadioButton;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.view.client.SingleSelectionModel;
import com.google.inject.Inject;
import com.google.web.bindery.event.shared.EventBus;
import com.gwtplatform.mvp.client.PopupViewImpl;

public class TopicListingPopupView extends PopupViewImpl implements
		TopicListingPopupPresenter.MyView {

	public interface Binder extends UiBinder<Widget, TopicListingPopupView> {
	}

	private final Widget widget;


	@UiField
	Label browserPurposeDescription;
	@UiField
	RadioButton orderAlphabetic;
	@UiField
	RadioButton orderNumberOfThoughts;
	@UiField
	RadioButton orderNumberOfReads;
	/**
	 * The main List.
	 */
	@UiField(provided = true)
	CellList<Topic> topTopics;
	@UiField
	Button selectTopic;
	@UiField
	Button addToExistingTopic;
	@UiField
	Button addToNewTopic;
	@UiField
	Button cancel;

	SingleSelectionModel<Topic> selectionModel;

	@Inject
	public TopicListingPopupView(final EventBus eventBus, final Binder binder,
			TopicListing topicListing) {
		super(eventBus);

		selectionModel = new SingleSelectionModel<Topic>();
		topTopics = new CellList<Topic>(topicListing);
		topTopics.setSelectionModel(selectionModel);
		widget = binder.createAndBindUi(this);
	}

	@Override
	public Widget asWidget() {
		return widget;
	}


	public RadioButton getOrderAlphabetic() {
		return orderAlphabetic;
	}

	public RadioButton getOrderNumberOfThoughts() {
		return orderNumberOfThoughts;
	}

	public RadioButton getOrderNumberOfReads() {
		return orderNumberOfReads;
	}

	public CellList<Topic> getTopicList() {
		return topTopics;
	}

	public Button getAddToSelectedTopic() {
		return addToExistingTopic;
	}

	public Button getAddToNewTopic() {
		return addToNewTopic;
	}

	public Button getCancel() {
		return cancel;
	}

	public SingleSelectionModel<Topic> getSelectionModel() {
		return selectionModel;
	}

	@Override
	public void refresh() {
		selectionModel.setSelected(selectionModel.getSelectedObject(), false);
	}

	@Override
	public Button getSelectTopic() {
		return selectTopic;
	}

	@Override
	public Label getBrowserPurposeDescription() {
		return browserPurposeDescription;
	}
}
